package com.yexs;

import com.didispace.swagger.EnableSwagger2Doc;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@EnableSwagger2Doc//可以看看和easy-mock的集成，方便前端调试和工作进度
//exclude表示自动配置时不包括Multipart配置
//@EnableAutoConfiguration(exclude = { MultipartAutoConfiguration.class })
@SpringBootApplication
//@ServletComponentScan
@MapperScan("com.yexs.dao.impl.mapper")
public class SpringbootFirstApplication {
    private static Logger log = LoggerFactory.getLogger(SpringbootFirstApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(SpringbootFirstApplication.class, args);
    }

    //通过RestTemplate消费 restful服务
    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder.build();
    }

    @Bean
    public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
        return (String... args) -> {
            //http://gturnquist-quoters.cfapps.io/api/random（随机返回json字符串）
            String quote = restTemplate.getForObject(
                    "http://gturnquist-quoters.cfapps.io/api/random", String.class);
            log.info("redis 测试：" + quote.toString());
        };
    }

    /**
     * 将 multipartResolver 指向我们刚刚创建好的继承 CommonsMultipartResolver 类的自定义文件上传处理类
     */
//    @Bean(name = "multipartResolver")
//    public MultipartResolver multipartResolver() {
//        CustomMultipartResolver customMultipartResolver = new CustomMultipartResolver();
//        return customMultipartResolver;
//    }


    /*@Bean
    public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
        //输出自动注入的bean
        return args -> {
            System.out.println("----args----");
            Arrays.asList(args).forEach(System.out::println);
            System.out.println("Let's inspect(视察) the beans provided by Spring Boot");

            String[] beanNames = ctx.getBeanDefinitionNames();
            Arrays.sort(beanNames);

            for (String beanName : beanNames) {
                System.out.println(beanName);
            }
            System.out.println("-------inspect bean end--------------");
        };
    }*/
}
